home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / os2 / pccts.zip / AST.H < prev    next >
C/C++ Source or Header  |  1992-12-08  |  3KB  |  99 lines

  1. /* Abstract syntax tree
  2.  *
  3.  * Macros, definitions
  4.  *
  5.  * SOFTWARE RIGHTS
  6.  *
  7.  * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
  8.  * Set (PCCTS) -- PCCTS is in the public domain.  An individual or
  9.  * company may do whatever they wish with source code distributed with
  10.  * PCCTS or the code generated by PCCTS, including the incorporation of
  11.  * PCCTS, or its output, into commerical software.
  12.  * 
  13.  * We encourage users to develop software with PCCTS.  However, we do ask
  14.  * that credit is given to us for developing PCCTS.  By "credit",
  15.  * we mean that if you incorporate our source code into one of your
  16.  * programs (commercial product, research project, or otherwise) that you
  17.  * acknowledge this fact somewhere in the documentation, research report,
  18.  * etc...  If you like PCCTS and have developed a nice tool with the
  19.  * output, please mention that you developed it using PCCTS.  In
  20.  * addition, we ask that this header remain intact in our source code.
  21.  * As long as these guidelines are kept, we expect to continue enhancing
  22.  * this system and expect to make other tools available as they are
  23.  * completed.
  24.  *
  25.  * ANTLR 1.06
  26.  * Terence Parr
  27.  * Purdue University
  28.  * 1989-1992
  29.  */
  30.  
  31. #define zzastOvfChk                                                        \
  32.             if ( zzast_sp <= 0 )                                        \
  33.             {                                                           \
  34.                 fprintf(stderr, zzStackOvfMsg, __FILE__, __LINE__);        \
  35.                 exit(-1);                                               \
  36.             }
  37.  
  38. #ifndef AST_FIELDS
  39. #define AST_FIELDS
  40. #endif
  41.  
  42. typedef struct _ast {
  43.             struct _ast *right, *down;
  44. #ifdef zzAST_DOUBLE
  45.             struct _ast *left, *up;
  46. #endif
  47.             AST_FIELDS
  48.         } AST;
  49.  
  50.  
  51. /* N o d e  a c c e s s  m a c r o s */
  52. #define zzchild(t)        (((t)==NULL)?NULL:(t->down))
  53. #define zzsibling(t)    (((t)==NULL)?NULL:(t->right))
  54.  
  55.  
  56. /* define global variables needed by #i stack */
  57. #define zzASTgvars                                                \
  58.     AST *zzastStack[ZZAST_STACKSIZE];                            \
  59.     int zzast_sp = ZZAST_STACKSIZE;
  60.  
  61. #define zzASTVars    AST *_ast = NULL, *_sibling = NULL, *_tail = NULL
  62. #define zzSTR        ( (_tail==NULL)?(&_sibling):(&(_tail->right)) )
  63. #define zzastCur    (zzastStack[zzast_sp])
  64. #define zzastArg(i)    (zzastStack[zztsp-i])
  65. #define zzastPush(p) zzastOvfChk; zzastStack[--zzast_sp] = p;
  66. #define zzastDPush    --zzast_sp
  67. #define zzastMARK    zztsp=zzast_sp;        /* Save state of stack */
  68. #define zzastREL    zzast_sp=zztsp;        /* Return state of stack */
  69. #define zzrm_ast    {zzfree_ast(*_root); _tail = _sibling = (*_root)=NULL;}
  70.  
  71. extern int zzast_sp;
  72. extern AST *zzastStack[];
  73.  
  74. #ifdef __STDC__
  75. void zzlink(AST **, AST **, AST **);
  76. AST *zzastnew();
  77. void zzsubchild(AST **, AST **, AST **);
  78. void zzsubroot(AST **, AST **, AST **);
  79. void zzpre_ast(AST *, void (*)(), void (*)(), void (*)());
  80. void zzfree_ast(AST *);
  81. AST *zztmake(AST *, ...);
  82. AST *zzdup_ast(AST *);
  83. void zztfree(AST *);
  84. void zzdouble_link(AST *, AST *, AST *);
  85.  
  86. #else
  87.  
  88. void zzlink();
  89. AST *zzastnew();
  90. void zzsubchild();
  91. void zzsubroot();
  92. void zzpre_ast();
  93. void zzfree_ast();
  94. AST *zztmake();
  95. AST *zzdup_ast();
  96. void zztfree();
  97. void zzdouble_link();
  98. #endif
  99.